﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Threading;
using System.Windows.Data;
using Microsoft.Forums.ForumsClient.Models;
using Microsoft.Forums.ForumsClient.Properties;

namespace Microsoft.Forums.ForumsClient.Views
{
    /// <summary>
    ///  Converts the logged in status into a forum store title
    /// </summary>
    public class ForumStoreTitleConverter : IValueConverter
    {

        /// <summary>
        /// Depending on the input value return a different forum store title
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || !(value is LogOnStatus))
                throw new ArgumentNullException("value","value must not be null and must be of type LogOnStatus");

            LogOnStatus logOnStatus = (LogOnStatus)value;

            if (logOnStatus == LogOnStatus.Authenticated && 
                AppDataModel.Instance != null)
            {
                return Resources.ForumStoreTitle + AppDataModel.Instance.CurrentUser.LogOnName;
            }
            else
            {
                return Resources.ForumStoreOfflineTitle;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException("ConvertBack is not supported for FormatToString");
        }

    }
}